<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <!-- <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
    </el-form-item> -->
    <el-form-item label="状态 1驳回 0拒绝 2未处理" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态 1驳回 0拒绝 2未处理"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contacts">
      <el-input v-model="dataForm.contacts" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="审核消息" prop="toExamineMessage">
      <el-input v-model="dataForm.toExamineMessage" placeholder="审核消息"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址"></el-input>
    </el-form-item>
    <el-form-item label="企业名称" prop="enterpriseName">
      <el-input v-model="dataForm.enterpriseName" placeholder="企业名称"></el-input>
    </el-form-item>
    <el-form-item label="企业logo" prop="enterpriseLogo">
      <el-input v-model="dataForm.enterpriseLogo" placeholder="企业logo"></el-input>
    </el-form-item>
    <el-form-item label="封面图" prop="coverImage">
      <el-input v-model="dataForm.coverImage" placeholder="封面图"></el-input>
    </el-form-item>
    <el-form-item label="视频" prop="video">
      <el-input v-model="dataForm.video" placeholder="视频"></el-input>
    </el-form-item>
    <el-form-item label="详细介绍" prop="introduce">
      <el-input v-model="dataForm.introduce" placeholder="详细介绍"></el-input>
    </el-form-item>
    <el-form-item label="其他联系方式" prop="otherContacts">
      <el-input v-model="dataForm.otherContacts" placeholder="其他联系方式"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          createTime: '',
          updateTime: '',
          status: '',
          contacts: '',
          phone: '',
          toExamineMessage: '',
          address: '',
          enterpriseName: '',
          enterpriseLogo: '',
          coverImage: '',
          video: '',
          introduce: '',
          otherContacts: ''
        },
        dataRule: {
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态 1驳回 0拒绝 2未处理不能为空', trigger: 'blur' }
          ],
          contacts: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          toExamineMessage: [
            { required: true, message: '审核消息不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '地址不能为空', trigger: 'blur' }
          ],
          enterpriseName: [
            { required: true, message: '企业名称不能为空', trigger: 'blur' }
          ],
          enterpriseLogo: [
            { required: true, message: '企业logo不能为空', trigger: 'blur' }
          ],
          coverImage: [
            { required: true, message: '封面图不能为空', trigger: 'blur' }
          ],
          video: [
            { required: true, message: '视频不能为空', trigger: 'blur' }
          ],
          introduce: [
            { required: true, message: '详细介绍不能为空', trigger: 'blur' }
          ],
          otherContacts: [
            { required: true, message: '其他联系方式不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/testing/settlein/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.createTime = data.settleIn.createTime
                this.dataForm.updateTime = data.settleIn.updateTime
                this.dataForm.status = data.settleIn.status
                this.dataForm.contacts = data.settleIn.contacts
                this.dataForm.phone = data.settleIn.phone
                this.dataForm.toExamineMessage = data.settleIn.toExamineMessage
                this.dataForm.address = data.settleIn.address
                this.dataForm.enterpriseName = data.settleIn.enterpriseName
                this.dataForm.enterpriseLogo = data.settleIn.enterpriseLogo
                this.dataForm.coverImage = data.settleIn.coverImage
                this.dataForm.video = data.settleIn.video
                this.dataForm.introduce = data.settleIn.introduce
                this.dataForm.otherContacts = data.settleIn.otherContacts
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/testing/settlein/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'status': this.dataForm.status,
                'contacts': this.dataForm.contacts,
                'phone': this.dataForm.phone,
                'toExamineMessage': this.dataForm.toExamineMessage,
                'address': this.dataForm.address,
                'enterpriseName': this.dataForm.enterpriseName,
                'enterpriseLogo': this.dataForm.enterpriseLogo,
                'coverImage': this.dataForm.coverImage,
                'video': this.dataForm.video,
                'introduce': this.dataForm.introduce,
                'otherContacts': this.dataForm.otherContacts
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
